﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _16_State
{
    public abstract class State
    {
        public abstract void WriteProgram(Worker w);
    }

    public class ForenoonState : State
    {
        public override void WriteProgram(Worker w)
        {
            if (w.Hour < 12)
            {
                Console.WriteLine("当前时间：{0}点上午工作，精神百倍", w.Hour);
            }
            else
            {
                w.SetState(new NoonState());
                w.WriteProgram();
            }
        }
    }

    public class NoonState : State
    {
        public override void WriteProgram(Worker w)
        {
            if (w.Hour < 13)
            {
                Console.WriteLine("当前时间：{0}点 饿了,午饭：犯困，午休。", w.Hour);
            }
            else
            {
                w.SetState(new AfternoonState());
                w.WriteProgram();
            }
        }
    }

    public class AfternoonState : State
    {
        public override void WriteProgram(Worker w)
        {
            if (w.Hour < 17)
            {
                Console.WriteLine("当前时间：{0}点 下午状态还不错,继续努力", w.Hour);
            }
            else
            {
                w.SetState(new EveningState());
                w.WriteProgram();
            }
        }
    }

    public class EveningState : State
    {
        public override void WriteProgram(Worker w)
        {
            if (w.TaskFinished)
            {
                w.SetState(new RestState());
                w.WriteProgram();
            }
            else
            {
                if (w.Hour < 21)
                {
                    Console.WriteLine("当前时间：{0}点 加班中，疲劳至极", w.Hour);
                }
                else
                {
                    w.SetState(new SleepingState());
                    w.WriteProgram();
                }
            }
        }
    }

    public class SleepingState : State
    {
        public override void WriteProgram(Worker w)
        {
            Console.WriteLine("当前时间：{0}点 要死了 睡觉", w.Hour);
        }
    }

    public class RestState : State
    {
        public override void WriteProgram(Worker w)
        {
            Console.WriteLine("当前时间：{0}点 下班回家", w.Hour);
        }
    }
}
